<template>
	<view class="index">
		<view class="headtop">
			<view class="headtitile">
				<text>创优客合伙人</text>
				<view @click="refresh">刷新</view>
			</view>
		</view>
		<view class="container">
			<view class="title">今日自营数据</view>
			<view class="list clearfix">
				<view class="li fl">
					<view class="top clearfix">
						<image src="../../static/images/tongji_xiaoshou.png" class="fl"></image>
						<view class="desc fl">销售额</view>
					</view>
					<view class="shuzi">￥{{jrzyData.money}}<text>元</text></view>
				</view>
				<view class="li fl">
					<view class="top clearfix">
						<image src="../../static/images/tongji_order.png" class="fl"></image>
						<view class="desc fl">订单总数</view>
					</view>
					<view class="shuzi">￥{{jrzyData.count}}<text>单</text></view>
				</view>
				<view class="li fl">
					<view class="top clearfix">
						<image src="../../static/images/tongji_fenrun.png" class="fl"></image>
						<view class="desc fl">分润金额</view>
					</view>
					<view class="shuzi">￥{{jrzyData.divide_money}}<text>元</text></view>
				</view>
				<view class="li fl">
					<view class="top clearfix">
						<image src="../../static/images/tongji_bili.png" class="fl"></image>
						<view class="desc fl">分润比例</view>
					</view>
					<view class="shuzi">{{jrzyData.ratio}}</view>
				</view>
			</view>
		</view>
		<view class="container">
			<view class="title">今日团队数据</view>
			<view class="list clearfix">
				<view class="li fl">
					<view class="top clearfix">
						<image src="../../static/images/tongji_xiaoshou.png" class="fl"></image>
						<view class="desc fl">销售额</view>
					</view>
					<view class="shuzi">￥{{jrtdData.money}}<text>元</text></view>
				</view>
				<view class="li fl">
					<view class="top clearfix">
						<image src="../../static/images/tongji_order.png" class="fl"></image>
						<view class="desc fl">订单总数</view>
					</view>
					<view class="shuzi">￥{{jrtdData.count}}<text>单</text></view>
				</view>
				<view class="li fl">
					<view class="top clearfix">
						<image src="../../static/images/tongji_fenrun.png" class="fl"></image>
						<view class="desc fl">分润金额</view>
					</view>
					<view class="shuzi">￥{{jrtdData.divide_money}}<text>元</text></view>
				</view>
				<view class="li fl">
					<view class="top clearfix">
						<image src="../../static/images/tongji_bili.png" class="fl"></image>
						<view class="desc fl">分润比例</view>
					</view>
					<view class="shuzi">{{jrtdData.ratio}}</view>
				</view>
			</view>
		</view>
		<view class="container">
			<view class="title clearfix">
				<view class="left fl">本周团队数据</view>
				<view class="right fr">{{bztdData.count}}单</view>
			</view>
			<view class="list clearfix">
				<view class="li fl">
					<view class="top clearfix">
						<image src="../../static/images/tongji_xiaoshou.png" class="fl"></image>
						<view class="desc fl">销售额</view>
					</view>
					<view class="shuzi">￥{{bztdData.money}}<text>元</text></view>
				</view>
				<view class="li fl">
					<view class="top clearfix">
						<image src="../../static/images/tongji_fenrun.png" class="fl"></image>
						<view class="desc fl">分润金额</view>
					</view>
					<view class="shuzi">￥{{bztdData.divide_money}}<text>元</text></view>
				</view>
			</view>
		</view>
		<view class="container">
			<view class="title clearfix">
				<view class="left fl">本月团队数据</view>
				<view class="right fr">{{bytdData.count}}单</view>
			</view>
			<view class="list clearfix">
				<view class="li fl">
					<view class="top clearfix">
						<image src="../../static/images/tongji_xiaoshou.png" class="fl"></image>
						<view class="desc fl">销售额</view>
					</view>
					<view class="shuzi">￥{{bytdData.money}}<text>元</text></view>
				</view>
				<view class="li fl">
					<view class="top clearfix">
						<image src="../../static/images/tongji_fenrun.png" class="fl"></image>
						<view class="desc fl">分润金额</view>
					</view>
					<view class="shuzi">￥{{bytdData.divide_money}}<text>元</text></view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		request
	} from '@/api/request';
	
	export default {
		data() {
			return {
				userData: [],
				jrzyData: {
					count: 0,
					divide_money: 0.00,
					money: 0.00,
					ratio: '40%'
				},
				jrtdData: {
					count: 0,
					divide_money: 0.00,
					money: 0.00,
					ratio: '5%'
				},
				bztdData: {
					count: 0,
					divide_money: 0.00,
					money: 0.00,
				},
				bytdData: {
					count: 0,
					divide_money: 0.00,
					money: 0.00,
				}
			}
		},
		created() {
			// 用户基本信息
			request({
				url: '/api/user/profile',
				method: 'GET',
				data: {},
				header: {
					'xx-token': uni.getStorageSync('token')
				}
			}).then((response) => {
				this.userData = response.data;
				
				this.getjrzyData(this.userData.id);
				
				this.getjrtdData(this.userData.id);
				
				this.getbztdData(this.userData.id);
				
				this.getbytdData(this.userData.id);
			}).catch((error) => {});
		},
		methods: {
			refresh(){
				this.getjrzyData(this.userData.id);
				
				this.getjrtdData(this.userData.id);
				
				this.getbztdData(this.userData.id);
				
				this.getbytdData(this.userData.id);
			},
			getjrzyData(user_id){
				uni.request({
					url: 'http://39.106.73.165:6603/td/user_today',
					data: {
						user_id: user_id,
					},
					method: 'POST',
					success: (res) => {
						this.jrzyData = res.data.data
					},
					fail(error) {
						uni.showToast({
							title: error,
							icon: 'none'
						})
					}
				})
			},
			getjrtdData(user_id){
				uni.request({
					url: 'http://39.106.73.165:6603/td/team_today',
					data: {
						user_id: user_id,
					},
					method: 'POST',
					success: (res) => {
						this.jrtdData = res.data.data
					},
					fail(error) {
						uni.showToast({
							title: error,
							icon: 'none'
						})
					}
				})
			},
			getbztdData(user_id){
				uni.request({
					url: 'http://39.106.73.165:6603/td/team_week',
					data: {
						user_id: user_id,
					},
					method: 'POST',
					success: (res) => {
						this.bztdData = res.data.data
					},
					fail(error) {
						uni.showToast({
							title: error,
							icon: 'none'
						})
					}
				})
			},
			getbytdData(user_id){
				uni.request({
					url: 'http://39.106.73.165:6603/td/team_month',
					data: {
						user_id: user_id,
					},
					method: 'POST',
					success: (res) => {
						this.bytdData = res.data.data
					},
					fail(error) {
						uni.showToast({
							title: error,
							icon: 'none'
						})
					}
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.index {
		width: 100%;
		margin: 0 auto;
		padding-bottom: 120rpx;
		
		.headtop {
			width: 100%;
			margin: 0 auto;
			position: relative;
			height: 166rpx;
			z-index: 200;
		
			.headtitile {
				width: 94%;
				margin: 0 auto;
				position: absolute;
				top: 60rpx;
				left: 3%;
				height: 96rpx;
				line-height: 96rpx;
		
				text {
					font-size: 32rpx;
					color: #FFFFFF;
					float: left;
					height: 96rpx;
					line-height: 96rpx;
				}
		
				view {
					font-size: 30rpx;
					color: #ECDEA4;
					float: right;
					height: 96rpx;
					line-height: 96rpx;
				}
			}
		}

		.container {
			width: 94%;
			margin: 0 auto 20rpx;
			border: 1rpx solid #454B57;
			border-radius: 10rpx;
			padding: 20rpx 20rpx 0 20rpx;
			box-sizing: border-box;

			.title {
				margin-top: 10rpx;
				margin-bottom: 29rpx;
				font-size: 30rpx;
				color: #ffffff;
				
				.left{
					font-size: 30rpx;
					color: #ffffff;
				}
				
				.right{
					font-size: 28rpx;
					color: #ffffff;
				}
			}

			.list {
				width: 100%;

				.li {
					width: 320rpx;
					border-radius: 10rpx;
					background: #242831;
					margin-right: 20rpx;
					margin-bottom: 20rpx;
					padding: 30rpx 0 26rpx 30rpx;
					box-sizing: border-box;
					
					.top{
						margin-bottom: 20rpx;
						
						image{
							width: 36rpx;
							height: 36rpx;
							margin-right: 10rpx;
						}
						
						.desc {
							font-size: 28rpx;
							color: #ffffff;
							height: 36rpx;
							line-height: 36rpx;
						}
					}

					.shuzi {
						font-size: 40rpx;
						color: #ffffff;
						font-weight: 700;
						
						text{
							font-size: 28rpx;
						}
					}
				}

				.li:nth-of-type(2n) {
					margin-right: 0;
				}
			}
		}
	}
</style>